package com.fulin.leetcode;

/**
 * TODO
 *
 * @Author fulin
 * @Date 2022/9/21 15:19
 **/
public class Num110_是否是高度平衡的二叉树 {
    public boolean isBalanced(TreeNode root) {
        if(root == null) return true;

        int leftHight = getHight(root.left);
        int rightHight = getHight(root.right);
        return Math.abs(leftHight - rightHight) > 1 ? false : isBalanced(root.left) && isBalanced(root.right);
    }

    private int getHight(TreeNode root) {
        if(root == null) return 0;

        return Math.max(getHight(root.left),getHight(root.right)) + 1;
    }
}
